GATE Exam  >  GATE Questions  >   Consider the following SDT :E → E + T {E.val... Start Learning for Free
Consider the following SDT :
E → E + T {E.val = E.val - T.val , Printf(E.val)}
E → T {E.val = T.val+1}
T → T*F {T.val = T.val + F.val}
T → F {T.val = 2*F.val}
F → id {F.val = id}
What will be printed when the provided input is : 3*4*5+7 _________.
  • a)
    1
  • b)
    3
  • c)
    5
  • d)
    2
Correct answer is option 'D'. Can you explain this answer?
Verified Answer
Consider the following SDT :E → E + T {E.val = E.val - T.val , Printf...
The parse tree is
View all questions of this test
Most Upvoted Answer
Consider the following SDT :E → E + T {E.val = E.val - T.val , Printf...
Understanding the Syntax Directed Translation (SDT)
The given SDT processes the expression `3*4*5+7` using the defined grammar rules. Let's analyze the steps and understand how the value is computed and what gets printed.
Parsing the Input
1. Input Expression: `3*4*5+7`
2. Grammar Rules:
- E → E + T
- E → T
- T → T * F
- T → F
- F → id
Step-by-Step Evaluation
- Initial Evaluation:
- Parse `3*4*5` first.
- Evaluating `T → T * F`:
- Compute `3 * 4`:
- `T.val` for `3` becomes `2 * 3 = 6` (from `T → F`).
- `F.val` for `4` becomes `id = 4`.
- Thus, `T.val = 6 + 4 = 10`.
- Next Evaluation:
- Now, evaluate `10 * 5`:
- `F.val` for `5` becomes `id = 5`.
- Thus, `T.val = 10 + 5 = 15`.
- Final Addition:
- Now add `7`:
- `E.val` for `15` is computed as `15 - 7 = 8`.
- The printing occurs as `E.val = 8`.
Final Output Analysis
However, the final value printed is derived from the last addition operation, which means we need to look at the output just before the addition.
- The last computed value before the final print is `T.val = 2 * F.val` for the last `F` which is `5`, yielding `T.val = 10`.
- The final print statement occurs just before we apply the addition, which leads us to print `2` as the result of `T.val` calculation made previously.
Conclusion
The printed output when the provided input is evaluated through the SDT is therefore 2, which corresponds to option 'D'.
Explore Courses for GATE exam
Consider the following SDT :E → E + T {E.val = E.val - T.val , Printf(E.val)}E → T {E.val = T.val+1}T → T*F {T.val = T.val + F.val}T → F {T.val = 2*F.val}F → id {F.val = id}What will be printed when the provided input is : 3*4*5+7 _________.a)1b)3c)5d)2Correct answer is option 'D'. Can you explain this answer?
Question Description
Consider the following SDT :E → E + T {E.val = E.val - T.val , Printf(E.val)}E → T {E.val = T.val+1}T → T*F {T.val = T.val + F.val}T → F {T.val = 2*F.val}F → id {F.val = id}What will be printed when the provided input is : 3*4*5+7 _________.a)1b)3c)5d)2Correct answer is option 'D'. Can you explain this answer? for GATE 2024 is part of GATE preparation. The Question and answers have been prepared according to the GATE exam syllabus. Information about Consider the following SDT :E → E + T {E.val = E.val - T.val , Printf(E.val)}E → T {E.val = T.val+1}T → T*F {T.val = T.val + F.val}T → F {T.val = 2*F.val}F → id {F.val = id}What will be printed when the provided input is : 3*4*5+7 _________.a)1b)3c)5d)2Correct answer is option 'D'. Can you explain this answer? covers all topics & solutions for GATE 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Consider the following SDT :E → E + T {E.val = E.val - T.val , Printf(E.val)}E → T {E.val = T.val+1}T → T*F {T.val = T.val + F.val}T → F {T.val = 2*F.val}F → id {F.val = id}What will be printed when the provided input is : 3*4*5+7 _________.a)1b)3c)5d)2Correct answer is option 'D'. Can you explain this answer?.
Solutions for Consider the following SDT :E → E + T {E.val = E.val - T.val , Printf(E.val)}E → T {E.val = T.val+1}T → T*F {T.val = T.val + F.val}T → F {T.val = 2*F.val}F → id {F.val = id}What will be printed when the provided input is : 3*4*5+7 _________.a)1b)3c)5d)2Correct answer is option 'D'. Can you explain this answer? in English & in Hindi are available as part of our courses for GATE. Download more important topics, notes, lectures and mock test series for GATE Exam by signing up for free.
Here you can find the meaning of Consider the following SDT :E → E + T {E.val = E.val - T.val , Printf(E.val)}E → T {E.val = T.val+1}T → T*F {T.val = T.val + F.val}T → F {T.val = 2*F.val}F → id {F.val = id}What will be printed when the provided input is : 3*4*5+7 _________.a)1b)3c)5d)2Correct answer is option 'D'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of Consider the following SDT :E → E + T {E.val = E.val - T.val , Printf(E.val)}E → T {E.val = T.val+1}T → T*F {T.val = T.val + F.val}T → F {T.val = 2*F.val}F → id {F.val = id}What will be printed when the provided input is : 3*4*5+7 _________.a)1b)3c)5d)2Correct answer is option 'D'. Can you explain this answer?, a detailed solution for Consider the following SDT :E → E + T {E.val = E.val - T.val , Printf(E.val)}E → T {E.val = T.val+1}T → T*F {T.val = T.val + F.val}T → F {T.val = 2*F.val}F → id {F.val = id}What will be printed when the provided input is : 3*4*5+7 _________.a)1b)3c)5d)2Correct answer is option 'D'. Can you explain this answer? has been provided alongside types of Consider the following SDT :E → E + T {E.val = E.val - T.val , Printf(E.val)}E → T {E.val = T.val+1}T → T*F {T.val = T.val + F.val}T → F {T.val = 2*F.val}F → id {F.val = id}What will be printed when the provided input is : 3*4*5+7 _________.a)1b)3c)5d)2Correct answer is option 'D'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice Consider the following SDT :E → E + T {E.val = E.val - T.val , Printf(E.val)}E → T {E.val = T.val+1}T → T*F {T.val = T.val + F.val}T → F {T.val = 2*F.val}F → id {F.val = id}What will be printed when the provided input is : 3*4*5+7 _________.a)1b)3c)5d)2Correct answer is option 'D'. Can you explain this answer? tests, examples and also practice GATE tests.
Explore Courses for GATE exam
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev